package jomi.fatiasdovos.fatias.parser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Jorge Machado
 * @date 29/Dez/2007
 * @time 1:47:22
 */
public class SourcesProperties extends jomm.utils.ConfigProperties
{

    private static SourcesProperties instance;


    public String getPath()
    {
        return "/jomi/fatiasdovos/fatias/parser/sources.properties";
    }

    public static SourcesProperties getInstance()
    {
        if(instance == null)
            instance = new SourcesProperties();
        return instance;
    }

    /**
     * Get property and convert it to float
     *
     * @param property to get and convert
     * @return float value
     */
    public static float getFloatProperty(String property)
    {
        return getInstance().getFloat(property);
    }

    /**
     * Get property and convert it to short
     *
     * @param property to get and convert
     * @return float value
     */
    public static short getShortProperty(String property)
    {
        return getInstance().getShort(property);
    }

    /**
     * Get property and convert it to boolean
     *
     * @param property to get and convert
     * @return float value
     */
    public static boolean getBooleanProperty(String property)
    {
        return getInstance().getBoolean(property);
    }

    /**
     * Get property and convert it to int
     *
     * @param property to get and convert
     * @return float value
     */
    public static int getIntProperty(String property)
    {
        return getInstance().getInt(property);
    }


    /**
     *
     * @param property to load
     * @return property value
     */
    public static String getProperty(String property)
    {
        return getInstance().getProp(property);
    }

    /**
     * @param propertyPrefix to load
     * @return a list of all property names hat starts with the given
     * prefix
     */
    public static List<String> getListProperties(String propertyPrefix)
    {
        return getInstance().getListProps(propertyPrefix);
    }

    /**
     * @param propertyPrefix to load
     * @return a list of all values hat starts with the given
     * prefix
     */
    public static List<String> getListValues(String propertyPrefix)
    {
        return getInstance().getListVals(propertyPrefix);
    }


    public static List<String> getListValuesByPrefix(String valuePrefix)
    {
        List<String> props = new ArrayList<String>();
        for (Map.Entry<Object,Object> property : getInstance().getProperties().entrySet())
        {
            if(((String)property.getValue()).startsWith(valuePrefix))
                props.add((String) property.getValue());
        }
        return props;
    }

    /**
     * @param propertyPrefix to load
     * @return a list of all values hat starts with the given
     * prefix
     */
    public static List<String> getListValuesOrderedByValue(String propertyPrefix)
    {
        return getInstance().getListValsOrderedByValue(propertyPrefix);
    }


    /**
     * @param propertyPrefix to load
     * @return a list of all values hat starts with the given
     * prefix
     */
    public static List<String> getListValuesOrderedByPropertyName(String propertyPrefix)
    {
        return getInstance().getListValsOrderedByPropertyName(propertyPrefix);
    }

}
